
====================
' This file was modified as part of an ASP.NET 2.0 Web project conversion.
' The class name was changed and the class modified to inherit from the abstract base class 
'''/ in file 'App_Code\Migrated\Stub_group_aspx_cs.cs'.
' During runtime, this allows other classes in your web application to bind and access 
' the code-behind page using the abstract base class.
' The associated content page 'group.aspx' was also modified to refer to the new class name.
' For more information on this code pattern, please refer to http://go.microsoft.com/fwlink/?LinkId=46995 
====================
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for group.
	''' </summary>
	Public Partial Class Migrated_group
		Inherits group

		Protected groupName As String = ""
		Protected groupNameOwner As String = ""
		Protected sMembersCount As String = ""
		Protected lblFriendshipPath As System.Web.UI.WebControls.Label
		Protected Label1 As System.Web.UI.WebControls.Label
		Protected dgGroupEvents As System.Web.UI.WebControls.DataGrid
		Protected grpID As Integer = -1
		Protected usr As User = Nothing
		Protected grp As Group = Nothing
		Protected grpEvents As ArrayList = Nothing
		Protected htPageConstants As New Hashtable()

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			'this.pageTemplate.PageTitle = PageTitles.GROUP_PAGE;

			' Auto login from an external link
			'AutoLogin( Request );

			usr = LoggedUser

			Me.initPageTitles(Constants.GROUP, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			If Constants.SHOW_GROUPS <> Constants.SHOW_ON Then
				Throw New Exception(Constants.ERROR_MESSAGE_NO_ACCESS)
			End If

			If Request.Params(Constants.GROUP_PARAM) = Nothing AndAlso Request.Params(Constants.GROUP_PARAM) = "" Then
				Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
			End If

			Try
				grpID = Convert.ToInt32(Request.Params(Constants.GROUP_PARAM))
			Catch
				Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
			End Try

			grp = Groups.GetGroupByID(grpID)

			If grp = Nothing Then
				Throw New Exception(Constants.ERROR_MESSAGE_GROUP_DOESNT_EXIST_ERROR)
			End If

			grpEvents = GroupEvents.LoadGroupEvents(grpID, Constants.MAX_GRID_EVENTS_ON_GROUP_PAGE)

			If usr <> Nothing AndAlso grp.Uid <> usr.ID Then
				grp.CountViews()
			End If

			groupName = grp.Name
			groupNameOwner = grp.Name + "'s"

			lblGroup.Text = (Me.GetPageConstText(htPageConstants, "CONST_PageTitle_TEXT")).Replace("[PARAM]", groupName)

			' init group photo
			Dim GrpPicture As GroupPicture = grp.DefaultPicture
			If GrpPicture <> Nothing Then
				imgGroup.ImageUrl = Pictures.GetPictureLargeThumbnailSrcFullURL(GrpPicture, "../")
				imgGroup.ToolTip = grp.Name
			Else
				imgGroup.ImageUrl = "../images/default_thumbnail.gif"
				imgGroup.ToolTip = grp.Name
			End If

			'set moderator
			hlModerator.Text = Users.GetUserByID(grp.Uid).Name
			hlModerator.NavigateUrl = "../" + Constants.MEMBERS + "?id=" + grp.Uid

			'init group since date
			lblGroupSince.Text = Constants.ARR_MONTHS(grp.CreationDate.Month - 1) + " " + grp.CreationDate.Year

			'init group viewed
			lblGroupViewed.Text = grp.TimesViewed.ToString()

			' init last update date
			lblLastUpdateDate.Text = grp.LastEditedDate.Day + "/" + grp.LastEditedDate.Month + "/" + grp.LastEditedDate.Year

			' init group pictures count
			Dim pics As ArrayList = grp.GetPictures()
			hlPhotos.Text = "View All <font class='main_text_opposite'>" + pics.Count.ToString() + "</font>" + " Picture"
			If pics.Count <> 1 Then
				hlPhotos.Text += "s"
			End If
			' Init group photos page
			hlPhotos.NavigateUrl = "../" + Constants.VIEW_GROUP_PHOTOS + "?" + Constants.GROUP_PARAM + "=" + grp.ID

			' init links
			If usr <> Nothing Then
				'hlAddComment.CommandArgument = usr.ID.ToString();
				'hlAddComment2.CommandArgument = usr.ID.ToString();

				If grp.Members.Contains(usr.ID) Then
					hlUnsubscribe.Text = Me.GetPageConstText(htPageConstants, "CONST_Unsubscribe_TEXT")
					hlUnsubscribe.NavigateUrl = "../" + Constants.CONFIRM_UNSUBSCRIBE + "?" + Constants.GROUP_PARAM + "=" + grp.ID
					hlAddToFriends.Visible = False
				Else
					hlAddToFriends.NavigateUrl = "../" + Constants.CONFIRM_JOIN_GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID
					hlUnsubscribe.Visible = False
				End If
				hlAddComment.NavigateUrl = "../" + Constants.FRIENDS_ADD_COMMENT + "?usr=" + usr.ID + "&" + Constants.GROUP_PARAM + "=" + grpID
				hlAddComment2.NavigateUrl = "../" + Constants.FRIENDS_ADD_COMMENT + "?usr=" + usr.ID + "&" + Constants.GROUP_PARAM + "=" + grpID
				hlAddComment3.NavigateUrl = "../" + Constants.FRIENDS_ADD_COMMENT + "?usr=" + usr.ID + "&" + Constants.GROUP_PARAM + "=" + grpID
			Else
				' Init for not logged user
				'hlAddToFriends.NavigateUrl = "../" + Constants.LOGIN_PAGE;
				hlAddToFriends.NavigateUrl = "../" + Constants.CONFIRM_JOIN_GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID
				hlUnsubscribe.Visible = False
				hlAddComment.NavigateUrl = "../" + Constants.FRIENDS_ADD_COMMENT + "?usr=-1&" + Constants.GROUP_PARAM + "=" + grpID
				hlAddComment2.NavigateUrl = "../" + Constants.FRIENDS_ADD_COMMENT + "?usr=-1&" + Constants.GROUP_PARAM + "=" + grpID
				hlAddComment3.NavigateUrl = "../" + Constants.FRIENDS_ADD_COMMENT + "?usr=-1&" + Constants.GROUP_PARAM + "=" + grpID
			End If

			hlAllBulletin.NavigateUrl = "../" + Constants.BULLETIN + "?" + Constants.GROUP_PARAM + "=" + grp.ID
			hlAllBlog.NavigateUrl = "../" + Constants.BLOG + "?" + Constants.GROUP_PARAM + "=" + grp.ID
			hlPostGroupBulletin.NavigateUrl = "../" + Constants.POST_BULLETIN + "?" + Constants.GROUP_PARAM + "=" + grp.ID
			hlSendMessage.NavigateUrl = "../" + Constants.SEND_MESSAGE + "?action=" + Constants.MESSAGE_TO_GROUP_ACTION + "&" + Constants.GROUP_PARAM + "=" + grp.ID
			hlSeeAllMembersUp.NavigateUrl = "../" + Constants.SEE_ALL_MEMBERS + "?" + Constants.GROUP_PARAM + "=" + grp.ID

			hlAddToFav.NavigateUrl = "../" + Constants.ADD_TO_FAVORITES + "?" + Constants.GROUP_PARAM + "=" + grp.ID
			hlForwardToFriend.NavigateUrl = "../" + Constants.SEND_MESSAGE + "?" + Constants.FORWARD_A_GROUP_PARAM + "=" + grp.ID + "&action=" + Constants.MESSAGE_FORWARD_A_GROUP_ACTION

			' init members count
			sMembersCount = grp.Members.Count.ToString()

			If Convert.ToInt32(sMembersCount) = 0 Then
				lblNoMembers.Visible = True
			End If


			' init group details table

			' set Category
			Dim lblCategory As New Label()
			Dim hlCategoryValue As New HyperLink()
			lblCategory.Text = Me.GetPageConstText(htPageConstants, "CONST_Category_TEXT")
			lblCategory.Font.Bold = True
			hlCategoryValue.Text = Constants.CATEGORIES.GetCategoryByID(grp.CatID).Name
			hlCategoryValue.NavigateUrl = "../" + Constants.CATEGORY_GROUPS + "?" + Constants.CATEGORY_PARAM + "=" + grp.CatID

			addTableRow(lblCategory, hlCategoryValue)

			' set Group Type
			Dim lblGroupTypeValue As New Label()
			Dim lblGroupType As New Label()
			lblGroupType.Text = Me.GetPageConstText(htPageConstants, "CONST_GroupType_TEXT")
			lblGroupType.Font.Bold = True
			lblGroupTypeValue.Text = IIf(grp.PublicGroup,Me.GetPageConstText(htPageConstants, "CONST_Public_TEXT"),Me.GetPageConstText(htPageConstants, "CONST_Private_TEXT"))
			lblGroupTypeValue.Text += "<img src='images/spacer.gif' width='140' height='1' /><b><a href='#grouptype' onclick=""popWinHelp('help_groups.aspx?helpID=" + Constants.GROUP_HELP_PAGE_GROUP_TYPE + "')"">Help</a></b>"
			addTableRow(lblGroupType, lblGroupTypeValue)

			' Clear session for the new searches
			Session(Constants.ssnAdvGroupSearchFilter) = Nothing

			' set Country
			Dim hlCountryValue As New HyperLink()
			Dim lblCountry As New Label()
			lblCountry.Text = Me.GetPageConstText(htPageConstants, "CONST_Country_TEXT")
			lblCountry.Font.Bold = True
			If grp.CountryID = -1 Then
				hlCountryValue.Text = ""
			Else
				hlCountryValue.Text = Constants.COUNTRIES.GetCountryByID(grp.CountryID).Name
				hlCountryValue.NavigateUrl = "../" + Constants.GROUP_SEARCH_RESULTS + "?" + Constants.COUNTRY_PARAM + "=" + grp.CountryID
			End If

			addTableRow(lblCountry, hlCountryValue)

			'set City
			Dim lblCity As New Label()
			Dim hlCityValue As New HyperLink()
			lblCity.Text = Me.GetPageConstText(htPageConstants, "CONST_City_TEXT")
			lblCity.Font.Bold = True
			If grp.City <> Nothing Then
				hlCityValue.Text = grp.City
				hlCityValue.NavigateUrl = "../" + Constants.GROUP_SEARCH_RESULTS + "?" + Constants.CITY_PARAM + "=" + grp.City
			End If

			addTableRow(lblCity, hlCityValue)

			'set Activities
			If grp.Activities <> Nothing AndAlso grp.Activities.Length > 0 Then
				Dim lblActivities As New Label()
				Dim lblActivitiesValue As New Label()
				lblActivities.Text = Me.GetPageConstText(htPageConstants, "CONST_Activities_TEXT")
				lblActivities.Font.Bold = True
				lblActivitiesValue.Text = grp.Activities
				addTableRow(lblActivities, lblActivitiesValue)
			End If

			' set Contacts
			If grp.Contacts <> Nothing AndAlso grp.Contacts.Length > 0 Then
				Dim lblContacts As New Label()
				Dim lblContactsValue As New Label()
				lblContacts.Text = Me.GetPageConstText(htPageConstants, "CONST_Contacts_TEXT")
				lblContacts.Font.Bold = True
				lblContactsValue.Text = grp.Contacts
				addTableRow(lblContacts, lblContactsValue)
			End If

			'set Charity
			If grp.Charity <> Nothing AndAlso grp.Charity.Length > 0 Then
				Dim lblCharityValue As New Label()
				Dim lblCharity As New Label()
				lblCharity.Text = Me.GetPageConstText(htPageConstants, "CONST_Charity_TEXT")
				lblCharity.Font.Bold = True
				lblCharityValue.Text = grp.Charity
				addTableRow(lblCharity, lblCharityValue)
			End If

			' set Image
			If grp.ImageURL <> "" AndAlso grp.ImageURL <> Nothing Then
				Dim lblFavImage As New Label()
				Dim hlFavImageURL As New HyperLink()
				lblFavImage.Text = Me.GetPageConstText(htPageConstants, "CONST_SeeImage_TEXT")
				lblFavImage.Font.Bold = True

				If grp.ImageURLName <> Nothing AndAlso grp.ImageURLName <> "" Then
					hlFavImageURL.Text = grp.ImageURLName
				End If

				hlFavImageURL.Attributes.Add("href", "#")
				hlFavImageURL.Attributes.Add("onclick", Me.constructImageURL(grp.ImageURL))

				addTableRow(lblFavImage, hlFavImageURL)
			End If

			' set Clip
			If grp.ClipURL <> "" AndAlso grp.ClipURL <> Nothing Then
				Dim lblClip As New Label()
				Dim hlClipURL As New HyperLink()
				lblClip.Text = Me.GetPageConstText(htPageConstants, "CONST_Watch_TEXT")
				lblClip.Font.Bold = True

				If grp.ClipURLName <> Nothing AndAlso grp.ClipURLName <> "" Then
					hlClipURL.Text = grp.ClipURLName
				End If

				hlClipURL.Attributes.Add("href", "#")
				hlClipURL.Attributes.Add("onclick", Me.constructMusicURL(grp.ClipURL))

				addTableRow(lblClip, hlClipURL)
			End If

			' set About Group
			lblAboutGroup.Text = grp.About
			lblAbout.Text = "About " + grp.Name

			' set songs
			Dim isThereASong As Boolean = False
			If grp.SongURL1 <> Nothing AndAlso grp.SongURL1 <> "" Then
				hlSong1.Attributes.Add("href", "#song")
				hlSong1.Attributes.Add("onclick", Me.constructMusicURL(grp.SongURL1))
				hlSong1.Text = grp.SongURL1
				If grp.SongURLName1 <> Nothing AndAlso grp.SongURLName1 <> "" Then
					hlSong1.Text = grp.SongURLName1
				End If
				isThereASong = True
			Else
				hlSong1.Visible = False
			End If

			If grp.SongURL2 <> Nothing AndAlso grp.SongURL2 <> "" Then
				hlSong2.Attributes.Add("href", "#song")
				hlSong2.Attributes.Add("onclick", Me.constructMusicURL(grp.SongURL2))
				hlSong2.Text = grp.SongURL2
				If grp.SongURLName2 <> Nothing AndAlso grp.SongURLName2 <> "" Then
					hlSong2.Text = grp.SongURLName2
				End If
				isThereASong = True
			Else
				hlSong2.Visible = False
			End If

			If grp.SongURL3 <> Nothing AndAlso grp.SongURL3 <> "" Then
				hlSong3.Attributes.Add("href", "#song")
				hlSong3.Attributes.Add("onclick", Me.constructMusicURL(grp.SongURL3))
				hlSong3.Text = grp.SongURL3
				If grp.SongURLName3 <> Nothing AndAlso grp.SongURLName3 <> "" Then
					hlSong3.Text = grp.SongURLName3
				End If
				isThereASong = True
			Else
				hlSong3.Visible = False
			End If

			If grp.ClipURL <> Nothing AndAlso grp.ClipURL <> "" Then
				hlClip.Attributes.Add("href", "#song")
				hlClip.Attributes.Add("onclick", Me.constructMusicURL(grp.ClipURL))
				hlClip.Text = grp.ClipURL
				If grp.ClipURLName <> Nothing AndAlso grp.ClipURLName <> "" Then
					hlClip.Text = grp.ClipURLName
				End If
				isThereASong = True
			Else
				hlClip.Visible = False
			End If

			trSongs.Visible = isThereASong

			' list Bands details if any
			Dim grpBands As GroupBands = GroupBands.GetGroupBandsByGroupID(grpID)
			If grpBands <> Nothing Then
				' set bands members
				If grpBands.Members <> Nothing AndAlso grpBands.Members.Length > 0 Then
					Dim lblGroupBandMembers As New Label()
					Dim lblGroupBandMembersValue As New Label()
					lblGroupBandMembers.Font.Bold = True

					lblGroupBandMembers.Text = Me.GetPageConstText(htPageConstants, "CONST_BandMembers_TEXT")
					lblGroupBandMembersValue.Text = grpBands.Members

					addTableRow(lblGroupBandMembers, lblGroupBandMembersValue)
				End If

				' set bands influences
				If grpBands.Influences <> Nothing AndAlso grpBands.Influences.Length > 0 Then
					Dim lblGroupBandInfluences As New Label()
					Dim lblGroupBandInfluencesValue As New Label()
					lblGroupBandInfluences.Font.Bold = True

					lblGroupBandInfluences.Text = Me.GetPageConstText(htPageConstants, "CONST_Influences_TEXT")
					lblGroupBandInfluencesValue.Text = grpBands.Influences

					addTableRow(lblGroupBandInfluences, lblGroupBandInfluencesValue)
				End If

				' set bands sounds like
				If grpBands.SoundsLike <> Nothing AndAlso grpBands.SoundsLike.Length > 0 Then
					Dim lblGroupBandSoundsLike As New Label()
					Dim lblGroupBandSoundsLikeValue As New Label()
					lblGroupBandSoundsLike.Font.Bold = True

					lblGroupBandSoundsLike.Text = Me.GetPageConstText(htPageConstants, "CONST_SoundsLike_TEXT")
					lblGroupBandSoundsLikeValue.Text = grpBands.SoundsLike

					addTableRow(lblGroupBandSoundsLike, lblGroupBandSoundsLikeValue)
				End If

				' set bands genres
				Dim tmpGenre As String = ""
				If grpBands.Genre1 > 0 Then
					tmpGenre = Constants.GENRE.GetGroupGenreByID(grpBands.Genre1).Name + ", "
				End If

				If grpBands.Genre2 > 0 Then
					tmpGenre += Constants.GENRE.GetGroupGenreByID(grpBands.Genre2).Name + ", "
				End If

				If grpBands.Genre3 > 0 Then
					tmpGenre += Constants.GENRE.GetGroupGenreByID(grpBands.Genre3).Name + ", "
				End If

				If tmpGenre.Length > 0 Then
					Dim lblGroupBandGenre As New Label()
					Dim lblGroupBandGenreValue As New Label()
					lblGroupBandGenre.Font.Bold = True

					lblGroupBandGenre.Text = Me.GetPageConstText(htPageConstants, "CONST_Genre_TEXT")
					lblGroupBandGenreValue.Text = tmpGenre.Substring(0, tmpGenre.Length - 2)

					addTableRow(lblGroupBandGenre, lblGroupBandGenreValue)
				End If

				' set bands site URL
				If grpBands.SiteURL <> Nothing AndAlso grpBands.SiteURL.Length > 0 Then
					Dim lblGroupBandSiteURL As New Label()
					Dim hlGroupBandSiteURLValue As New HyperLink()
					lblGroupBandSiteURL.Font.Bold = True

					lblGroupBandSiteURL.Text = Me.GetPageConstText(htPageConstants, "CONST_BandWebsite_TEXT")
					hlGroupBandSiteURLValue.Text = getBeginning(HttpUtility.HtmlEncode(grpBands.SiteURL), Constants.MAX_LINK_LENGTH)
					hlGroupBandSiteURLValue.NavigateUrl = grpBands.SiteURL
					hlGroupBandSiteURLValue.Target = "_blank"

					addTableRow(lblGroupBandSiteURL, hlGroupBandSiteURLValue)
				End If

				' set bands record label
				If grpBands.RecordLabel <> Nothing AndAlso grpBands.RecordLabel.Length > 0 AndAlso grpBands.RecordLabel <> Constants.LABEL_DEFAULT_VALUE Then
					Dim lblGroupBandRecordLabel As New Label()
					Dim lblGroupBandRecordLabelValue As New Label()
					lblGroupBandRecordLabel.Font.Bold = True

					lblGroupBandRecordLabel.Text = Me.GetPageConstText(htPageConstants, "CONST_RecordLabel_TEXT")
					lblGroupBandRecordLabelValue.Text = grpBands.RecordLabel

					addTableRow(lblGroupBandRecordLabel, lblGroupBandRecordLabelValue)
				End If

				' set bands label type
				If grpBands.LabelType > 0 Then
					Dim lblGroupBandLabelType As New Label()
					Dim lblGroupBandLabelTypeValue As New Label()
					lblGroupBandLabelType.Font.Bold = True

					lblGroupBandLabelType.Text = Me.GetPageConstText(htPageConstants, "CONST_LabelType_TEXT")
					lblGroupBandLabelTypeValue.Text = Constants.LABELTYPES.GetLabelTypeByID(grpBands.LabelType).Name

					addTableRow(lblGroupBandLabelType, lblGroupBandLabelTypeValue)
				End If
			End If

			' init AdminLinks

			If usr <> Nothing AndAlso usr.Status = Constants.appAdmin Then
				tblAdminLinks.Visible = True

				' add table header
				Dim controls As New ArrayList()

				Dim lblAdminLinks As New Label()
				lblAdminLinks.Text = Me.GetPageConstText(htPageConstants, "CONST_AdminLinks_TEXT")
				controls.Add(lblAdminLinks)
				addTableRow("notes", controls)

				' add featured group link
				controls = New ArrayList()

				Dim lbMarkFeature As New LinkButton()
				If grp.FeatureGroup Then
					lbMarkFeature.Text = Me.GetPageConstText(htPageConstants, "CONST_FeaturedGroup_TEXT")
				Else
					lbMarkFeature.Text = Constants.AL_MARK_AS_FEATURED.Replace("{member}", grp.Name)
				End If
				AddHandler lbMarkFeature.Click, AddressOf Me.lbMarkFeature_Click
				controls.Add(lbMarkFeature)
				addTableRow("notes_td_transparent", controls)

				' add special settings link
				controls = New ArrayList()

				Dim hlSpecialGroup As New HyperLink()
				hlSpecialGroup.Font.Bold = True
				hlSpecialGroup.Text = Constants.AL_CHANGE_SPECIAL_SETTINGS.Replace("{member}", grp.Name)
				hlSpecialGroup.NavigateUrl = "../" + Constants.SPECIAL_SETTINGS + "?" + Constants.GROUP_PARAM + "=" + grp.ID
				controls.Add(hlSpecialGroup)

				addTableRow("notes_td_transparent", controls)
			End If

			If grpEvents.Count > 0 Then
				' set Events
				For Each result As GroupEvent In grpEvents
					Dim months As String() = Constants.ARR_MONTHS
					Dim lblEventDate As New Label()
					Dim lblEventPlace As New Label()
					Dim hlEvent As New HyperLink()
					lblEventDate.Text = result.DateTimeEvent.ToString("dddd, MMMM dd h:mm tt")

					hlEvent.NavigateUrl = "../" + Constants.VIEW_GROUP_EVENTS + "?" + Constants.GROUP_PARAM + "=" + result.GroupID
					hlEvent.Text = result.Venue
					If (result.ZipCode <> Nothing) AndAlso (result.ZipCode.Trim() <> String.Empty) Then
						lblEventPlace.Text = result.ZipCode + ", " + result.City
					Else
						lblEventPlace.Text = result.City
					End If

					addTableRow(lblEventDate, hlEvent, lblEventPlace)
				Next

				hlViewAllEvents.NavigateUrl = "../" + Constants.VIEW_GROUP_EVENTS + "?" + Constants.GROUP_PARAM + "=" + grpID
			Else
				trEventsShows.Visible = False
				trEventsShowsHead.Visible = False
			End If

			hlViewMoreComments.NavigateUrl = "../" + Constants.GROUP_COMMENTS_PAGE + "?" + Constants.GROUP_PARAM + "=" + grpID
			hlViewMoreCommentsBottom.NavigateUrl = hlViewMoreComments.NavigateUrl
			Dim commentsCountToCompare As Integer = grp.Comments.Count
			If LoggedUser <> Nothing AndAlso LoggedUser.ID = grp.Uid Then
				commentsCountToCompare += grp.NewComments.Count
			End If

			If commentsCountToCompare <= Constants.COMMENTS_ON_PROFILE_PAGE Then
				hlViewMoreComments.Visible = False
				hlViewMoreCommentsBottom.Visible = False
				lblCommentsLine.Visible = False
				lblLine.Visible = False
			End If

			' Bind data
			If Not IsPostBack Then
				If grp.Members.Count <> 0 Then
					BindList()
				End If
				BindGrid(dgMessages, "comments")
				BindGrid(dgBlog, "blog")
				BindGrid(dgBulletins, "bulletin")
			End If
			'if (usr != null && grp.Uid.Equals(usr.ID)) 
			'{	
			'	hlAddComment3.Visible = false;
			'	lblCommentsLine.Visible = false;
			'}
		End Sub

		' add row to details table
		Private Sub addTableRow(ByVal ctlName As Control, ByVal ctlValue As Control)
			Dim tr As New TableRow()
			Dim td1 As New TableCell()
			Dim td2 As New TableCell()

			td1.Controls.Add(ctlName)
			td2.Controls.Add(ctlValue)
			td1.Width = 100
			td2.Width = 210
			td1.CssClass = "main_text"
			td2.CssClass = "main_text"
			tr.Cells.Add(td1)
			tr.Cells.Add(td2)

			tblUserDetails.Rows.Add(tr)
		End Sub

		' add row to details table
		Private Sub addTableRow(ByVal ctlName1 As Control, ByVal ctlName2 As Control, ByVal ctlName3 As Control)
			Dim tr As New TableRow()
			Dim td1 As New TableCell()
			Dim td2 As New TableCell()
			Dim td3 As New TableCell()

			td1.Controls.Add(ctlName1)
			td2.Controls.Add(ctlName2)
			td3.Controls.Add(ctlName3)
			td1.Wrap = False
			td1.CssClass = "main_text"
			td2.CssClass = "main_text"
			td3.CssClass = "main_text"
			td1.Width = Unit.Percentage(30)
			td2.Width = Unit.Percentage(45)
			td3.Width = Unit.Percentage(25)
			tr.Cells.Add(td1)
			tr.Cells.Add(td2)
			tr.Cells.Add(td3)

			tblGroupEvents.Rows.Add(tr)
		End Sub

		' add Row to Admin links table
		Private Sub addTableRow(ByVal cssclass As String, ByVal ctls As ArrayList)
			Dim tr As New TableRow()
			Dim td As New TableCell()
			td.CssClass = cssclass
			For Each ctl As Control In ctls
				td.Controls.Add(ctl)
			Next
			tr.Cells.Add(td)
			tblAdminLinks.Rows.Add(tr)
		End Sub

		'		public ICollection CreateDataSource() 
		Public Overloads Overrides Function CreateDataSource() As ICollection
			Dim grp As BO.Group = Groups.GetGroupByID(grpID)

			Dim startIndex As Integer = 0
			Dim endIndex As Integer = startIndex + Constants.MAX_PICTURES_ON_WELCOME_PAGE
			Dim i As Integer
			Dim dt As New DataTable()
			Dim dr As DataRow

			dt.Columns.Add(New DataColumn("ImageURL", GetType(String)))
			dt.Columns.Add(New DataColumn("Name", GetType(String)))
			dt.Columns.Add(New DataColumn("OnlineImg", GetType(String)))
			dt.Columns.Add(New DataColumn("FriendID", GetType(String)))
			dt.Columns.Add(New DataColumn("URL", GetType(String)))
			dt.Columns.Add(New DataColumn("FullName", GetType(String)))

			Dim temp As UserPicture
			Dim grpMembers As GroupsUsers = grp.Members
			Dim nMembersCount As Integer = grpMembers.Count
			Dim imagesOnLastRow As Integer = 0
			Dim t As Integer = 0
			Dim counter As Integer = 0

			endIndex = Math.Min(endIndex, nMembersCount)
			t = (endIndex - startIndex)
			Math.DivRem(t, Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE, imagesOnLastRow)
			counter = 0

			Dim LoggedUsersList As ArrayList = Common.Utils.GetLoggedUsersIDs()

			For Each gm As BO.GroupMember In grpMembers
				If counter >= startIndex AndAlso counter < endIndex Then
					dr = dt.NewRow()
					temp = gm.User.DefaultPicture
					If temp <> Nothing Then
						dr(0) = Pictures.GetPictureSrcFullURL(temp, True, "../")
					Else
						dr(0) = "../images/default_thumbnail.gif"
					End If
					dr(1) = getBeginning(HttpUtility.HtmlEncode(gm.User.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
					If LoggedUsersList.Contains(gm.User.ID) Then
						dr(2) = "../images/online_status.gif"
					Else
						dr(2) = "../images/spacer.gif"
					End If
					dr(3) = gm.User.ID
					dr(4) = "../" + Constants.MEMBERS + "?id=" + gm.User.ID
					dr(5) = gm.User.Name
					dt.Rows.Add(dr)
				End If
				System.Math.Max(System.Threading.Interlocked.Increment(counter),counter - 1)
			Next

			If imagesOnLastRow <> 0 Then
				blankImagesCount = Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE - imagesOnLastRow
				i = imagesOnLastRow
				While i < Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE
					dr = dt.NewRow()
					dr(0) = "../images/spacer.gif"
					dr(1) = ""
					dr(2) = "../images/spacer.gif"
					dt.Rows.Add(dr)
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While
			End If

			Dim dv As New DataView(dt)
			Return dv
		End Function

		'		public void BindList() 
		Public Overloads Overrides Sub BindList()
			dlAllMembers.DataSource = CreateDataSource()
			dlAllMembers.DataBind()

			Dim itemsCount As Integer = dlAllMembers.Items.Count
			Dim blankImageIndex As Integer = itemsCount - blankImagesCount
			Dim i As Integer = 0
			i = blankImageIndex
			While i < itemsCount
				(DirectCast(dlAllMembers.Items(i).FindControl("hlName"), System.Web.UI.WebControls.HyperLink)).CssClass = "empty_image"
				(DirectCast(dlAllMembers.Items(i).FindControl("hlPhoto"), System.Web.UI.WebControls.HyperLink)).CssClass = "empty_image"
				System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
			End While
		End Sub

		Protected Function CreateDataSourceForGrid(ByVal type As String) As ICollection
			Dim commentsList As New ArrayList()
			Dim blogsList As New ArrayList()
			Dim bulList As New ArrayList()
			Dim dt As New DataTable()
			Dim startIndex As Integer = -1
			Dim endIndex As Integer = -1
			Dim LoggedUsersList As ArrayList = Common.Utils.GetLoggedUsersIDs()

			' List group's comments
			Select Case type
				Case "comments"
					commentsList = grp.Comments
					startIndex = 0
					endIndex = startIndex + Math.Min(commentsList.Count, Constants.COMMENTS_ON_PROFILE_PAGE)
					'endIndex = startIndex + commentsList.Count;	
					dt.Columns.Add(New DataColumn("SenderID", GetType(Integer)))
					dt.Columns.Add(New DataColumn("SenderName", GetType(String)))
					dt.Columns.Add(New DataColumn("SenderImageURL", GetType(String)))
					dt.Columns.Add(New DataColumn("OnlineImg", GetType(String)))
					dt.Columns.Add(New DataColumn("MemberURL", GetType(String)))
					dt.Columns.Add(New DataColumn("Date", GetType(String)))
					dt.Columns.Add(New DataColumn("Time", GetType(String)))
					dt.Columns.Add(New DataColumn("Comment", GetType(String)))
					dt.Columns.Add(New DataColumn("CommentID", GetType(String)))
					dt.Columns.Add(New DataColumn("ButtonsVisibility", GetType(Boolean)))
					dt.Columns.Add(New DataColumn("RejectText", GetType(String)))
					dt.Columns.Add(New DataColumn("SenderNameFull", GetType(String)))
					dt.Columns.Add(New DataColumn("RemoveVisibility", GetType(Boolean)))
					dt.Columns.Add(New DataColumn("OnClickJS", GetType(String)))

					Exit Select
				Case "blog"
					startIndex = 0
					endIndex = startIndex + Constants.MAX_MESSAGES_ON_MEMBERS_PAGE

					dt.Columns.Add(New DataColumn("MessageID", GetType(Integer)))
					dt.Columns.Add(New DataColumn("Date", GetType(String)))
					dt.Columns.Add(New DataColumn("URL", GetType(String)))
					dt.Columns.Add(New DataColumn("FriendID", GetType(String)))
					dt.Columns.Add(New DataColumn("SenderName", GetType(String)))
					dt.Columns.Add(New DataColumn("Subject", GetType(String)))
					dt.Columns.Add(New DataColumn("ViewMsgURL", GetType(String)))
					dt.Columns.Add(New DataColumn("OnClickJS", GetType(String)))

					blogsList = Messages.GetGroupBlogs(grp.ID)
					Exit Select
				Case "bulletin"
					startIndex = 0
					endIndex = startIndex + Constants.MAX_MESSAGES_ON_MEMBERS_PAGE

					dt.Columns.Add(New DataColumn("MessageID", GetType(Integer)))
					dt.Columns.Add(New DataColumn("Date", GetType(String)))
					dt.Columns.Add(New DataColumn("URL", GetType(String)))
					dt.Columns.Add(New DataColumn("FriendID", GetType(String)))
					dt.Columns.Add(New DataColumn("SenderName", GetType(String)))
					dt.Columns.Add(New DataColumn("Subject", GetType(String)))
					dt.Columns.Add(New DataColumn("ViewMsgURL", GetType(String)))
					dt.Columns.Add(New DataColumn("OnClickJS", GetType(String)))

					bulList = Messages.GetGroupBulletins(grp.ID, 0, -1)

					hlAllBulletin.Visible = True

					Exit Select
			End Select

			If blogsList.Count = 0 AndAlso type = "blog" Then
				dgBlog.Visible = False
				hlAllBlog.Visible = False
				lblEmptyBlog.Visible = True
ElseIf commentsList.Count = 0 AndAlso type = "comments" Then
				dgMessages.Visible = False
				lblNoComments.Visible = True
ElseIf bulList.Count = 0 AndAlso type = "bulletin" Then
				dgBulletins.Visible = False
				'hlAllBulletin.Text = this.GetPageConstText(htPageConstants, "CONST_PostBulletin_TEXT");
				'hlAllBulletin.NavigateUrl = "../" + Constants.POST_BULLETIN + "?" + Constants.GROUP_PARAM + "=" + grp.ID;
				hlAllBulletin.Visible = False
				lblEmptyBulletins.Visible = True
			Else
				Dim curCommentDate As DateTime
				Dim curBlogDate As DateTime
				Dim curBulletinDate As DateTime
				Dim temp As UserPicture
				Dim curSender As User
				Dim grpComment As GroupComment
				Dim blog As GroupBlog
				Dim bul As GroupBulletinMessage

				Dim dr As DataRow

				' List group's comments
				Dim i As Integer = startIndex
				While i < endIndex
					dr = dt.NewRow()

					Select Case type
						Case "comments"
							endIndex = Math.Min(endIndex, commentsList.Count)
							grpComment = DirectCast(commentsList(i), GroupComment)
							curCommentDate = grpComment.[Date]
							curSender = Users.GetUserByID(grpComment.PostedByUserID)

							dr(0) = grpComment.PostedByUserID
							dr(1) = getBeginning(HttpUtility.HtmlEncode(curSender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
							dr(11) = curSender.Name
							temp = curSender.DefaultPicture
							If temp <> Nothing Then
								dr(2) = Pictures.GetPictureSrcFullURL(temp, True, "../")
							Else
								dr(2) = Constants.DEFAULT_THUMBNAIL_IMAGE_URL
							End If

							If LoggedUsersList.Contains(curSender.ID) Then
								dr(3) = "../images/online_status.gif"
							Else
								dr(3) = "../images/spacer.gif"
							End If

							'if(curSender.Status == Users.STATUS_ACTIVE)
							dr(4) = Users.ComposeMemeberLink(curSender)
							dr(13) = Users.ComposeMemeberLinkOnClickJS(curSender, trUserCanceledMessage)

							dr(5) = curCommentDate.DayOfWeek + ", " + Constants.ARR_MONTHS(curCommentDate.Month - 1) + " " + curCommentDate.Day + ", " + curCommentDate.Year
							dr(6) = curCommentDate.ToShortTimeString()
							dr(7) = grpComment.Comment
							dr(8) = grpComment.ID

							If grpComment.CommentStatus = GroupComment.Status.ucsNew Then
								dr(9) = True
								dr(10) = "Reject"
							Else
								dr(9) = False
								'if(action == Constants.FRIENDS_COMMENTS_EDIT_ACTION)
								dr(10) = "Remove"
							End If

							If LoggedUser <> Nothing Then
								If grp.Uid = LoggedUser.ID OrElse LoggedUser.ID = grpComment.PostedByUserID Then
									dr(12) = True
								Else
									dr(12) = False
								End If
							Else
								dr(12) = False
							End If
							Exit Select
						Case "blog"
							endIndex = Math.Min(endIndex, blogsList.Count)
							blog = DirectCast(blogsList(i), GroupBlog)
							curBlogDate = blog.DateSent
							dr(0) = blog.ID
							dr(1) = Constants.ARR_MONTHS(curBlogDate.Month - 1) + " " + curBlogDate.Day + "<br />" + curBlogDate.ToShortTimeString()

							dr(2) = Users.ComposeMemeberLink(blog.Sender)
							dr(7) = Users.ComposeMemeberLinkOnClickJS(blog.Sender, trUserCanceledMessage)

							dr(3) = blog.SenderID.ToString()
							dr(4) = getBeginning(HttpUtility.HtmlEncode(blog.Sender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
							dr(5) = Server.HtmlEncode(blog.Subject)
							dr(6) = "../" + Constants.VIEW_BLOG_COMMENTS + "?id=" + blog.ID + "&" + Constants.GROUP_PARAM + "=" + grp.ID
							Exit Select
						Case "bulletin"
							endIndex = Math.Min(endIndex, bulList.Count)
							bul = DirectCast(bulList(i), GroupBulletinMessage)
							curBulletinDate = bul.DateSent
							dr(0) = bul.ID
							dr(1) = Constants.ARR_MONTHS(curBulletinDate.Month - 1) + " " + curBulletinDate.Day + "<br />" + curBulletinDate.ToShortTimeString()
							dr(2) = "../" + Constants.MEMBERS + "?id=" + bul.SenderID.ToString()

							dr(3) = Users.ComposeMemeberLink(bul.Sender)
							dr(7) = Users.ComposeMemeberLinkOnClickJS(bul.Sender, trUserCanceledMessage)

							dr(4) = getBeginning(HttpUtility.HtmlEncode(bul.Sender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
							dr(5) = Server.HtmlEncode(bul.Subject)
							dr(6) = "../" + Constants.VIEW_MESSAGE + "?id=" + bul.ID + "&" + Constants.GROUP_PARAM + "=" + grpID + "&" + Constants.MSGBOX_PARAM + "=" + Constants.MSGBOX_BULLETIN
							Exit Select
					End Select
					dt.Rows.Add(dr)
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While
			End If
			Dim dv As New DataView(dt)
			Return dv
		End Function

		Protected Sub BindGrid(ByVal gridName As DataGrid, ByVal type As String)
			'init datagrid with database data ordered by "orederBy" param
			gridName.DataSource = CreateDataSourceForGrid(type)
			gridName.DataBind()
		End Sub
		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.dgMessages.ItemCommand, AddressOf Me.dgMessages_ItemCommand
		End Sub
#End Region

		Private Sub lbMarkFeature_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			If usr <> Nothing AndAlso usr.Status = Constants.appAdmin Then
				If Groups.GetFeaturedGroup().ID = grpID Then
					Groups.SetFeaturedGroup(0)
				Else
					Groups.SetFeaturedGroup(grpID)
				End If
				Response.Redirect(Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grpID)
			Else
				Common.Utils.RedirectToLoginPage(Page)
			End If
		End Sub

		Private Sub dgMessages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
			Dim grp As Group = Groups.GetGroupByID(grpID)
			Dim lbPushed As LinkButton = DirectCast(e.CommandSource, LinkButton)
			Dim cmd As String = e.CommandName

			Select Case cmd
				Case "Reject"
					' reject/remove comment
					grp.RemoveComment(Convert.ToInt32(e.CommandArgument))
					Exit Select
				Case "Approve"
					'approve comment
					grp.ApproveComment(Convert.ToInt32(e.CommandArgument))
					Exit Select
			End Select
			BindGrid(dgMessages, "comments")
		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
		'    public System.Web.UI.HtmlControls.HtmlForm Form1 {
		Public Overloads Overrides ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_Form1
			End Get
		End Property
		'set { Migrated_Form1 = value; }
	End Class
End Namespace






